//
//  CommentSuccessHeader.m
//  LvXi_newVersion
//
//  Created by 王敏 on 16/9/5.
//  Copyright © 2016年 SJT. All rights reserved.
//

#import "CommentSuccessHeader.h"

#import "CommentSuccessViewController.h"

#import "CommentController.h"

@interface CommentSuccessHeader()

@property(nonatomic,strong)UIImageView * imageView;

@property(nonatomic,strong)UILabel * label;

@property(nonatomic,strong)UIButton * btn;

@property(nonatomic,strong)UIView * line;

@property(nonatomic,strong)UIButton * addCommenButton;
@end
@implementation CommentSuccessHeader
-(id)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Smiling-face"]];
        self.imageView.size = self.imageView.image.size;
        [self addSubview:self.imageView];
        
        self.label = [[UILabel alloc] initWithFrame:CGRectZero];
        self.label.text = @"感谢您的评价";
        self.label.font = [UIFont systemFontOfSize:15];
        [self addSubview:self.label];
        
        self.line = [[UIView alloc] initWithFrame:CGRectZero];
        self.line.size = CGSizeMake(self.width, 0.5);
        self.line.backgroundColor = HexColor(@"#2CB034");
        [self addSubview:self.line];
        
        self.btn = [[UIButton alloc] initWithFrame:CGRectZero];
        self.btn.userInteractionEnabled = NO;
        self.btn.backgroundColor = HexColor(@"#EEEEEE");
        self.btn.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.btn setTitleColor:HexColor(@"#2CB034") forState:UIControlStateNormal];
        [self.btn setTitle:@"为你推荐" forState:UIControlStateNormal];
        [self.btn setImage:[UIImage imageNamed:@"recommended"] forState:UIControlStateNormal];
        [self addSubview:self.btn];
        
        self.addCommenButton = [[UIButton alloc] initWithFrame:CGRectZero];
        self.addCommenButton.backgroundColor = HexColor(@"#3CB034");
        [self.addCommenButton addRadius:5];
        [self.addCommenButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.addCommenButton.titleLabel.font = [UIFont systemFontOfSize:12];
        [self.addCommenButton setTitle:@"添加评价" forState:UIControlStateNormal];
        [self.addCommenButton addTarget:self action:@selector(addCommenButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.addCommenButton];
       
    }
    return self;
}

-(void)setStyle:(CommentSuccessViewControllerStyle)style{
    _style = style;
    switch (_style) {
        case CommentSuccessViewControllerStyleComOrder:{
            self.label.text = @"您的订单已经完成，等待收货吧!";
            self.imageView.image = [UIImage imageNamed:@"fk-dui"];
        }break;
        case CommentSuccessViewControllerStyleRecGoods:{
            self.label.text = @"您已成功收到宝贝，快来评价一下吧!";
            self.imageView.image = [UIImage imageNamed:@"fk-dui"];
        }break;
        case CommentSuccessViewControllerStyleComSuccess:{
            self.label.text = @"感谢您的评价";
            self.imageView.image = [UIImage imageNamed:@"Smiling-face"];
        }break;
        default:
            break;
    }
    [self setNeedsLayout];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.imageView.centerX = self.width * 0.5;
    self.imageView.y = 2*globalMargin;
    
    self.label.size = [self.label.text sizeInAre:MaxSize font:self.label.font];
    self.label.y = self.imageView.botton + globalMargin;
    self.label.centerX = self.imageView.centerX;
    self.btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0,0);
    self.btn.titleEdgeInsets = UIEdgeInsetsMake(0, globalMargin, 0, -globalMargin);
    self.btn.width = self.btn.currentImage.size.width + [self.btn.currentTitle sizeInAre:MaxSize font:self.btn.titleLabel.font].width + 3*globalMargin;
    self.btn.height = self.btn.currentImage.size.height;
    
    if(self.style == CommentSuccessViewControllerStyleRecGoods){
        self.addCommenButton.hidden = NO;
        self.addCommenButton.size = CGSizeMake(self.width-2*globalMargin, 30);
        self.addCommenButton.centerX = self.width*0.5;
        self.addCommenButton.y = self.label.botton+globalMargin;
        
        self.line.x = 0;
        self.line.y = self.addCommenButton.botton + self.btn.height;
        

        self.btn.centerX = self.width*0.5;
        self.btn.centerY = self.line.centerY;
       
    }else{
        self.addCommenButton.hidden = YES;
        self.line.x = 0;
        self.line.y = self.label.botton + self.btn.height;
        self.btn.centerX = self.width*0.5;
        self.btn.centerY = self.line.centerY;
    }
    
}

-(void)addCommenButtonClick:(UIButton*)button{
    CommentController * vc = [[CommentController alloc] init];
    [[self getCurrentVC].navigationController pushViewController:vc animated:YES];
}
@end
